<?php


namespace core\entity;


use core\lib\BotAPI;

class Message {

    /**
     * @var int
     */
    protected $id;

    /**
     * @var string
     */
    protected $raw;

    /**
     * @var array
     */
    protected $format;

    /**
     * Message constructor.
     * @param $input
     */
    public function __construct($input) {
        $this->id = $input['message_id'];
        $this->raw = $input['raw_message'];
        $this->format = $input['message'];
    }

    /**
     * 获得消息字符串
     * @return string
     */
    public function string(): string {
        return $this->raw;
    }

    public function format(): array {
        return $this->format;
    }

    /**
     * 撤回消息
     * @param int $delay
     */
    public function recall($delay = 0) {
        usleep($delay * 1000);
        bot()->recallMessage($this->id);
    }

}
